//https://leetcode.cn/problems/basic-calculator-ii/

class Solution {
public:
    int calculate(string s) {
        char op = '+';
        vector<int> temp;
        for (int i = 0; i < s.size();)
        {
            if (s[i] == ' ')
            {
                i++;
            }
            else if (s[i] >= '0' && s[i] <= '9')
            {
                int nums = 0;
                while (s[i] >= '0' && s[i] <= '9')
                {
                    nums = nums * 10 + (s[i] - '0');
                    i++;
                }
                if (op == '+') temp.push_back(nums);
                else if (op == '-') temp.push_back(-nums);
                else if (op == '*') temp.back() *= nums;
                else temp.back() /= nums;

            }
            else
            {
                op = s[i];
                i++;
            }
        }

        int ret = 0;
        for (auto e : temp)
        {
            ret += e;
        }

        return ret;

    }
};